<template>
  <div class="main">
      <el-alert style="margin-bottom:10px"
        title="为了打造绿色良好的环境,一经发现违规词汇帖子-20分,发现外部链接-20分,图片不通过审核-20分,70分以下帖子自动删除"
        type="warning"
      >
      </el-alert>
      <mavon-editor 
      
        @imgAdd="handleEditorImgAdd"
        v-model="node.cbContext"
        :codeStyle="1"
        ref="md"

      />
    <div class="nodeInfo">
             <el-alert style="margin-bottom:10px"
        title="帖子一旦发布无法修改,只能删除,每日发布帖子数量有限,请谨慎发布,如发现水贴将会进行后期删除!"
        type="warning"
      >
      </el-alert>
        <el-form>
            <el-form-item label="标题">
                <el-input v-model="node.cbName"></el-input>
            </el-form-item>
            <el-form-item label="描述">
                <el-input v-model="node.cbMess"></el-input>
            </el-form-item>
             <el-form-item label="栏目"><br>
               <el-select v-model="node.cbAlbum" filterable placeholder="请选择">
                <el-option
                  v-for="item in album"
                  :key="item.cbId"
                  :label="item.cbName"
                  :value="item.cbId">
                </el-option>
              </el-select>
            </el-form-item>

            <!-- <el-form-item label="权限"><br>
                <el-checkbox label="评论"></el-checkbox>
                <el-checkbox label="收藏"></el-checkbox>
            </el-form-item> -->

              <el-form-item :label="'目前文章评分:'+node.cbSercurityScore">
                  <el-button size="mini" @click="detectione()">重新检测</el-button>
            </el-form-item>
            
              <el-form-item label="今天还能发布:80">
            </el-form-item>
             <el-form-item label="发布须知">
                <el-checkbox v-model="node.statment" label="《免责声明》"></el-checkbox>
            </el-form-item>
              <el-form-item>
                  <el-button size="small" type="success" @click="iis">发布</el-button>
            </el-form-item>
        </el-form>
    </div>
 </div>

</template>

<script>
import qs from "qs"
export default {
  data(){
    return{
      node:{
        cbName:" ",
        cbMess:" ",
        cbAuthen:null,
        cbSercurityScore:100,
        statment:null,
        cbContext:" ",
        cbAlbum:null,
      },
      album:[
          {
            abName:null,
            abId:null
          }

      ],
      detection:null,

      
    }
  },
  methods:{
    detectione(){
      this.$http.post("/cbnode/verifity",qs.stringify({
        cbName:this.node.cbName,
        cbMess:this.node.cbMess,
        cbContext:this.node.cbContext
      })).then(va=>{
          this.$alert(va.data.message)
          this.node.cbSercurityScore = va.data.data
      })
    },
    iis(){
      if(this.node.statment!=true){
      this.$alert("请勾选免责声明")
        return
      }
      this.detectione()
      if(this.node.cbSercurityScore<100){
        this.$alert("请修改敏感内容后提交")
        return
      }else{
        if(this.node.cbContext.length<30){
          this.$alert("内容长度疑似水贴")
          return
        }
      if(this.node.cbAlbum==null){
        this.$alert("请选择一个栏目")
        return
      }
      this.node.cbContext=this.$refs.md.d_render
             // 提交
      this.$http.post("/cbnode/node",qs.stringify(this.node)).then(va=>{
         this.$alert(va.data.message)
         if(va.data.code==200){
           this.$router.push("/forum/"+va.data.data)
         }  
      })
      }
 
    },
    handleEditorImgAdd(pos, $file){
      let formdata = new FormData()
      formdata.append('file', $file)
      this.$http.post("/file/uploadFile",formdata).then(va=>{
         if(va.data.code==209){
           this.$alert(va.data.message)
           this.node.cbSercurityScore=this.node.cbSercurityScore-20
         }
         this.$refs.md.$img2Url(pos,va.data.data);
      })
    },
  },
  created(){
    // 获取栏目
    this.$http.get("/cbalbum/AlbumAll").then(va=>{
      this.album=va.data.data
    })
  }
}
</script>

<style scoped lang="less">
  
     .main{
        width: 70%;
        height: auto;
        background: #fff;
        margin: 30px auto;
    }
    .nodeInfo{
        width: 100%;
        height: auto;
        margin-top: 10px;
        padding: 30px;
             box-shadow:  0 0 12px rgba(0,0,0,0.1);
    }
     @media  screen and (max-width: 1300px) {
         .main{
             width: 100% !important;
         }
     }
</style>